<template>
	<view class="content">
		<!-- <scroll-view scroll-y class="left-aside">
			<view v-for="(item, index) in list" :key="item.id" class="f-item b-b" :class="{active: index === currentIndex}" @click="tabtap(item, index)">
				{{item.name}}
			</view>
		</scroll-view>
		<scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll" :scroll-top="tabScrollTop">
			<view v-for="item in slist" :key="item.id" class="s-list" :id="'main-'+item.id">
				<text class="s-item">{{item.name}}</text>
				<view class="t-list">
					<view @click="navToList(titem)" class="t-item" v-for="(titem, index) in item.childlist" :key="index">
						<image :src="titem.image"></image>
						<text>{{titem.name}}</text>
					</view>
				</view>
			</view>
		</scroll-view> -->
		<view class="sss">
			<view class="hsf">
				话术分类
			</view>
			<view class="xhs">
				选择一个治疗项目，即可精准筛选最佳回复话术
			</view>
		</view>
		<view class="bins">
			<view class="q">
				沟通类型
			</view>
			<view class="listy">
				<view class="ccc" v-for="(item, index) in list" :key="item.id" @click="gotonew(index)">
					<image class="w" :src="item.image" mode=""></image>
					<view class="faf">
						{{item.name}}
					</view>
				</view>

			</view>
			<!-- <view class="q">
				聊天场合
			</view>
			<view class="listy">
				<view class="ccc">
					<image class="w" src="../../static/1.png" mode=""></image>
					<view class="faf">
						是的发放
					</view>
				</view> 
				
			</view> -->
		</view>
		<view class="kaipi" @tap="maip">
			开通VIP ，享受精确匹配特权
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				sizeCalcState: false,
				tabScrollTop: 0,
				currentIndex: 0,
				list: [],
				flist: [],
				slist: [],
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			maip: function() {
				uni.navigateTo({
					url: "/pages/maiVIP/maiVIP"
				})
			},
			gotonew: function(id) {
				uni.navigateTo({
					url: `/pages/news/index?id=` + id
				})
			},
			async loadData(cb) {
				this.$http.get('category').then(res => {
					this.list = res.data
					if (this.list.length) {
						this.currentIndex = 0
						this.getSlist()
					}
					cb && cb()
				})
			},
			getSlist() {
				this.slist = this.list[this.currentIndex].childlist
			},
			//一级分类点击
			tabtap(item, index) {
				this.currentIndex = index
				this.getSlist()
			},
			//右侧栏滚动
			asideScroll(e) {
				if (!this.sizeCalcState) {
					this.calcSize();
				}
				let scrollTop = e.detail.scrollTop;
				let tabs = this.slist.filter(item => item.top <= scrollTop).reverse();
				if (tabs.length > 0) {
					this.currentId = tabs[0].pid;
				}
			},
			//计算右侧栏每个tab的高度等信息
			calcSize() {
				let h = 0;
				this.slist.forEach(item => {
					let view = uni.createSelectorQuery().select("#main-" + item.id);
					view.fields({
						size: true
					}, data => {
						item.top = h;
						h += data.height;
						item.bottom = h;
					}).exec();
				})
				this.sizeCalcState = true;
			},
			navToList(item) {
				uni.navigateTo({
					url: `/pages/product/list?cat_id=` + item.id
				})
			}
		},
		onPullDownRefresh() {
			this.loadData(() => {
				uni.stopPullDownRefresh()
			})
		}
	}
</script>

<style lang='scss'>
	.kaipi {
		width: 80%;
		padding: 20px 0;
		text-align: center;
		color: #333;
		background: #ffce66;
		border-radius: 500px;
		margin: 0 auto;
		margin-top: 5%;
		margin-bottom: 5%; 
	}

	.faf {
		width: 80%;
		margin-left: 10%;
		text-align: center;
		padding: 5px 10px;
		font-size: 12px;
		border-radius: 500px;
		background: rgb(242, 242, 242);
		margin-top: 10px;
		color: #000;
	}

	.w {
		width: 120rpx;
		height: 120rpx;

		border-radius: 50%;
		overflow: hidden;
	}

	.listy {
		width: 100%;

	}

	.listy::after {
		display: block;
		content: "";
		clear: both;
	}

	.listy>view {
		width: 25%;
		float: left;
		text-align: center;
	}

	.q {
		padding: 20px 20px; 
		font-weight: bold;
		font-size: 25px;
	}

	.bins {
		background: $page-color-light;
		width: 100%;
		min-height: 100px;
		border-radius: 20px 20px 0 0;
		overflow: hidden;
		margin-top: -70px;
	}

	.sss {
		padding: 15px 20px;
		width: 100%; 
		padding-bottom: 100px;
	}

	.xhs {
		color: #999;
		font-size: 15px;
		padding: 10px 0;

	}

	.hsf {
		color: #fff;
		font-weight: bold;
		font-size: 25px;
	}

	page,
	.content {
		height: 100%; 
		overflow: auto;
	}

	.left-aside {
		flex-shrink: 0;
		width: 200upx;
		height: 100%; 
	}

	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100upx;
		font-size: 28upx;
		color: $font-color-base;
		position: relative;

		&.active {
			color: $base-color;
			background: #f8f8f8;

			&:before {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 36upx;
				width: 8upx;
				background-color: $base-color;
				border-radius: 0 4px 4px 0;
				opacity: .8;
			}
		}
	}

	.right-aside {
		flex: 1;
		overflow: hidden;
		padding-left: 20upx;
	}

	.s-item {
		display: flex;
		align-items: center;
		height: 70upx;
		padding-top: 8upx;
		font-size: 28upx;
		color: $font-color-dark;
	}

	.t-list {
		display: flex;
		flex-wrap: wrap;
		width: 100%; 
		padding-top: 12upx;

		&:after {
			content: '';
			flex: 99;
			height: 0;
		}
	}

	.t-item {
		flex-shrink: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 176upx;
		font-size: 26upx;
		color: #666;
		padding-bottom: 20upx;

		image {
			width: 140upx;
			height: 140upx;
		}
	}
</style>
